<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>作业详情 - 析码无界</title>
    <link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.4/css/bootstrap.min.css">
    <link rel="stylesheet" href="http://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css">
    <script src="http://cdn.bootcss.com/jquery/1.11.2/jquery.min.js"></script>
    <script src="http://cdn.bootcss.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
    <style>
        body {
            font-family: 'Microsoft YaHei', sans-serif;
            background-color: #f5f5f5;
        }
        .navbar {
            border-radius: 0;
            background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
            border: none;
        }
        .navbar-brand {
            color: white !important;
            font-weight: bold;
        }
        .navbar-nav > li > a {
            color: rgba(255,255,255,0.9) !important;
        }
        .panel {
            border: none;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
            border-radius: 8px;
        }
        .panel-heading {
            background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
            color: white;
            border-radius: 8px 8px 0 0;
        }
        .btn-primary {
            background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
            border: none;
        }
        .assignment-info {
            background: white;
            padding: 20px;
            border-radius: 4px;
            margin-bottom: 20px;
        }
        .submission-info {
            background: #f8f9fa;
            padding: 15px;
            border-radius: 4px;
            margin-bottom: 20px;
        }
        .avatar-container {
            display: inline-block;
            margin-right: 10px;
            vertical-align: middle;
        }
        .student-avatar {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            border: 2px solid rgba(255,255,255,0.8);
            object-fit: cover;
            cursor: pointer;
            transition: transform 0.2s;
        }
        .student-avatar:hover {
            transform: scale(1.1);
        }
    </style>
</head>
<body>
    <!-- 导航栏 -->
    <nav class="navbar navbar-default">
        <div class="container-fluid">
            <div class="navbar-header">
                <a class="navbar-brand" href="/student" style="display: flex; align-items: center;">
                    <div class="avatar-container">
                        <img th:src="${session.student?.avatar != null and !session.student.avatar.isEmpty() ? '/' + session.student.avatar : ''}" 
                             class="student-avatar"
                             th:onclick="'location.href=\'' + @{/student/settings} + '\''"
                             onerror="if(this.src.indexOf('data:image') === -1) { this.onerror=null; this.src=''; }"
                             alt="头像">
                    </div>
                    <span><i class="fa fa-graduation-cap"></i> 析码无界 - 学生管理平台</span>
                </a>
            </div>
            <ul class="nav navbar-nav">
                <li><a th:href="@{/student/assignment/list}"><i class="fa fa-bell"></i> 任务提醒</a></li>
                <li><a th:href="@{/student/courses}"><i class="fa fa-book"></i> 我的课程</a></li>
            </ul>
            <ul class="nav navbar-nav navbar-right">
                <li><a href="/"><i class="fa fa-sign-out"></i> 退出登录</a></li>
            </ul>
        </div>
    </nav>

    <div class="container" style="margin-top: 20px;">
        <div th:if="${error}" class="alert alert-danger" th:text="${error}"></div>
        <div th:if="${message}" class="alert alert-success" th:text="${message}"></div>
        
        <!-- 作业信息 -->
        <div class="panel panel-default">
            <div class="panel-heading">
                <h3 class="panel-title"><i class="fa fa-file-text"></i> 作业详情</h3>
            </div>
            <div class="panel-body">
                <div class="assignment-info">
                    <h3 th:text="${assignment?.title} ?: '无标题'"></h3>
                    <hr>
                    <div style="margin: 15px 0;">
                        <strong>作业内容：</strong>
                        <p style="margin-top: 10px; white-space: pre-wrap;" th:text="${assignment?.content} ?: '无内容描述'"></p>
                    </div>
                    <div style="margin-top: 20px;">
                        <span><i class="fa fa-calendar"></i> 发布时间：<span th:text="${assignment?.publishTime != null ? #dates.format(assignment.publishTime, 'yyyy-MM-dd HH:mm') : '-'}"></span></span>
                        <span style="margin-left: 30px;"><i class="fa fa-clock-o"></i> 截止时间：<span th:text="${assignment?.deadline != null ? #dates.format(assignment.deadline, 'yyyy-MM-dd HH:mm') : '-'}"></span></span>
                    </div>
                </div>
                
                <!-- 已提交信息 -->
                <div th:if="${submission != null}" class="submission-info">
                    <h4><i class="fa fa-check-circle"></i> 已提交</h4>
                    <p><strong>提交时间：</strong><span th:text="${submission?.submitTime != null ? #dates.format(submission.submitTime, 'yyyy-MM-dd HH:mm') : '-'}"></span></p>
                    <div th:if="${submission?.content != null and !submission.content.isEmpty()}">
                        <strong>提交内容：</strong>
                        <p style="white-space: pre-wrap;" th:text="${submission.content}"></p>
                    </div>
                    <div th:if="${submission?.fileName != null}">
                        <strong>上传文件：</strong>
                        <a th:href="@{'/uploads/assignments/' + ${submission.fileName}}" th:text="${submission.fileName}">
                            <i class="fa fa-download"></i> 下载
                        </a>
                    </div>
                    <div th:if="${submission?.score != null}">
                        <strong>分数：</strong><span th:text="${submission.score}"></span> 分
                    </div>
                    <div th:if="${submission?.comment != null and !submission.comment.isEmpty()}">
                        <strong>教师评语：</strong>
                        <p th:text="${submission.comment}"></p>
                    </div>
                    <div th:if="${submission?.score == null}" style="margin-top: 10px;">
                        <small class="text-muted"><i class="fa fa-info-circle"></i> 作业已提交，等待教师批改</small>
                    </div>
                </div>
                
                <!-- 提交表单：如果已批改（有分数），则隐藏；否则显示为"修改提交" -->
                <div th:if="${submission == null or submission.score == null}" class="panel panel-default" style="margin-top: 20px;">
                    <div class="panel-heading">
                        <h4 class="panel-title">
                            <i class="fa fa-edit"></i> 
                            <span th:if="${submission != null}">修改提交</span>
                            <span th:if="${submission == null}">提交作业</span>
                        </h4>
                    </div>
                    <div class="panel-body">
                        <div th:if="${submission != null}" class="alert alert-info">
                            <i class="fa fa-info-circle"></i> 您可以修改已提交的作业内容，重新提交将覆盖之前的提交。
                        </div>
                        <form th:action="@{/student/assignment/submit}" method="post" enctype="multipart/form-data">
                            <input type="hidden" name="assignmentId" th:value="${assignment?.id}"/>
                            
                            <div class="form-group">
                                <label>作业内容（文本）</label>
                                <textarea class="form-control" name="content" rows="8" 
                                          placeholder="请输入作业内容..." th:text="${submission?.content}"></textarea>
                            </div>
                            
                            <div class="form-group">
                                <label>上传文件（可选）</label>
                                <input type="file" class="form-control" name="file" accept=".doc,.docx,.pdf,.txt,.zip,.rar">
                                <small class="help-block">支持格式：doc, docx, pdf, txt, zip, rar（最大10MB）</small>
                                <div th:if="${submission?.fileName != null}">
                                    <p style="margin-top: 10px;">当前文件：<span th:text="${submission.fileName}"></span></p>
                                    <small>重新上传将覆盖原文件</small>
                                </div>
                            </div>
                            
                            <div class="form-group">
                                <button type="submit" class="btn btn-primary">
                                    <i class="fa fa-save"></i> 
                                    <span th:if="${submission != null}">更新提交</span>
                                    <span th:if="${submission == null}">提交作业</span>
                                </button>
                                <a th:href="@{/student/assignment/list}" class="btn btn-default">
                                    <i class="fa fa-arrow-left"></i> 返回列表
                                </a>
                            </div>
                        </form>
                    </div>
                </div>
                
                <!-- 已批改提示 -->
                <div th:if="${submission != null and submission.score != null}" class="alert alert-success" style="margin-top: 20px;">
                    <h5><i class="fa fa-check-circle"></i> 作业已批改</h5>
                    <p>您的作业已被教师批改，无法再次修改。如需重新提交，请联系教师。</p>
                    <a th:href="@{/student/assignment/list}" class="btn btn-default">
                        <i class="fa fa-arrow-left"></i> 返回列表
                    </a>
                </div>
            </div>
        </div>
    </div>
</body>
</html>

